mui.init();
var url = ""
var id_card = "";
mui.plusReady(function() {
	var self = plus.webview.currentWebview();
	open_id = self.open_id;
	type = self.type;

	//获取验证码
	mui(".button").on("tap", "img", function() {
		getImage();
	});

	//确认提交并绑定
	mui(".get_photo").on("tap", ".mui-btn", function() {
		if(id_card.length == 0) {
			mui.toast("请先拍照")
		} else {
			BindCard();
		}
	});
});

function BindCard() {
	require(["bind"], function(bind) {
		bind.OnGetUserByPhoto(id_card,function(data){
			OnOpenWindow("./forget.html", "forget.html",{url:url,id_card:id_card})
			mui.toast("请设置密码")
		});
	});
}

function getImage() {
	var cmr = plus.camera.getCamera();
	cmr.captureImage(function(path) {
		console.log('保存照片到系统相册：');
		console.log(path);
		plus.zip.compressImage({ //压缩文件
				src: path,
				dst: "_doc/gallery/id.jpg",
				overwrite: true,
				quality: 20,
			},
			function() {
				require(["upload", "request", "bind"], function(upload, request, bind) {
					upload.Upload("_doc/gallery/id.jpg", function(files) {
						if(files.length > 0) {
							bind.OnGetOcrInfo(files[0], function(data) {
								id_card = data.id_card;
								url = request.Main_Host + data.url;
								showImg(request.Main_Host + data.url);
							});
						} else {
							mui.toast("识别失败")
						}
					});
				});
			},
			function(error) {
				alert("Compress error!");
			});
	}, function(e) {
		console.log('取消拍照');
	}, {
		filename: '_doc/gallery/',
		index: 1
	});
}

function showImg(url) {
	document.querySelector(".show2").setAttribute("src", url);
	document.querySelector(".mui-btn").style = "display: block;";
}